package cn.com.sparkle.paxos.event;

import cn.com.sparkle.paxos.NodeState;
import cn.com.sparkle.paxos.net.NetNode;

public abstract class NodeStateChangeEvent implements Event {
	public final static int LOSE_CONNECT = 1;
	public final static int OPEN_CONNECT = 2;
	public final static int BEAT_HEART = 3;

	@Override
	public void event(Object... args) {
		int s = (Integer) args[0];
		switch (s) {
		case LOSE_CONNECT:
			loseConnect((NetNode) args[1]);
			break;
		case OPEN_CONNECT:
			openConnect((NetNode) args[1]);
			break;
		case BEAT_HEART:
			beatHeart((NodeState) args[1]);
			break;
		default:
			throw new RuntimeException("not supported arguments :" + s);
		}
	}

	public final static void doLoseConnectEvent(EventsManager eventsManager,
			NetNode nNode) {
		eventsManager.doEvent(NodeStateChangeEvent.class, LOSE_CONNECT, nNode);
	}

	public final static void doOpenConnectEvent(EventsManager eventsManager,
			NetNode nNode) {
		eventsManager.doEvent(NodeStateChangeEvent.class, OPEN_CONNECT, nNode);
	}

	public final static void doBeatHeartEvent(EventsManager eventsManager,
			NodeState nState) {
		eventsManager.doEvent(NodeStateChangeEvent.class, BEAT_HEART, nState);
	}

	public abstract void loseConnect(NetNode nNode);

	public abstract void openConnect(NetNode nNode);

	public abstract void beatHeart(NodeState nState);
}
